package com.dayuanit.dy16.atm.controller;

import com.dayuanit.dy16.atm.dto.ResponseDTO;
import com.dayuanit.dy16.atm.service.ICardService;
import com.dayuanit.dy16.atm.vo.TransferRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

@RestController
public class CardController extends BaseController {

    @Autowired
    private ICardService cardService;

    AtomicInteger count = new AtomicInteger(0);

    @RequestMapping("/card/openaccount")
    public ResponseDTO openaccount(String password, String confirmPwd) {
        cardService.openaccount(password, confirmPwd,getUserId());
        count.addAndGet(1);
        return ResponseDTO.success();
    }

    @RequestMapping("/card/deposit")
    public ResponseDTO deposit(long cardId, String password, String amount) {
        cardService.deposit(cardId, password, amount, getUserId());
        return ResponseDTO.success();
    }

    @RequestMapping("/card/tranfer")
    public ResponseDTO tranfer(TransferRequestVO transferRequestVO) {
//        cardService.tranfer(transferRequestVO, getUserId());
        cardService.delayTransfer(transferRequestVO, getUserId());
        return ResponseDTO.success();
    }

    @RequestMapping("/card/queryMyCard")
    public ResponseDTO queryMyCard() {
        return ResponseDTO.success(cardService.queryMyCard(getUserId()));
    }
}
